﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LogEntry.cs" company="DissingNelleman">
//   
// All rights reserved. </copyright>
// <summary>
//   The log entry.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace ServiceLibrary.Models.Base
{
    using System;

    using NHibernate.Mapping.ByCode.Conformist;

    using ServiceLibrary.Models.Domain;

    /// <summary>
    /// The log entry.
    /// </summary>
    public class LogEntry : Entity
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the action type.
        /// </summary>
        public virtual Enums.LogEntryActionType ActionType { get; set; }

        /// <summary>
        /// Gets or sets the edited object id.
        /// </summary>
        public virtual Guid EditedObjectID { get; set; }

        /// <summary>
        /// Gets or sets the editor.
        /// </summary>
        public virtual User Editor { get; set; }

        /// <summary>
        /// Gets or sets the object type.
        /// </summary>
        public virtual Enums.LogEntryType ObjectType { get; set; }

        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        public virtual string Text { get; set; }

        /// <summary>
        /// Gets or sets the timestamp.
        /// </summary>
        public virtual DateTime Timestamp { get; set; }

        #endregion
    }

    /// <summary>
    /// The log entry mapping.
    /// </summary>
    public class LogEntryMapping : ClassMapping<LogEntry>
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="LogEntryMapping"/> class.
        /// </summary>
        public LogEntryMapping()
        {
            this.Property(x => x.Text, m => m.Length(int.MaxValue / 2));
            this.Property(x => x.Timestamp);
            this.ManyToOne(x => x.Editor);
            this.Property(x => x.ObjectType);
            this.Property(x => x.ActionType);
        }

        #endregion
    }
}